import pandas as pd

"""
导出本次需要计算的数据
"""

df_artisans = pd.read_csv('data/meirong/artisans_bj.csv')
df_orders = pd.read_csv('data/meirong/sample_orders.csv')
df_times = pd.read_csv('data/meirong/sample_times.csv')
df_address = df_artisans[['id', 'lon', 'lat']]
df_address['lon'] = df_address['lon'] / (10 ** 6)
df_address['lat'] = df_address['lat'] / (10 ** 6)
df_address['start'] = 0
df_address['stop'] = 0
# df_address = df_address.append(df_orders[['id', 'lon', 'lat', 'start', 'stop']])
df_address['lon'] = df_address['lon'].astype(float).round(3)
df_address['lat'] = df_address['lat'].astype(float).round(3)
df_address.to_csv('data/sample/artisans.csv')

df_orders = df_orders[['id', 'lon', 'lat', 'start', 'stop']]
df_orders['lon'] = df_orders['lon'].astype(float).round(3)
df_orders['lat'] = df_orders['lat'].astype(float).round(3)
df_orders.sort_values(['start', 'stop'], inplace=True)
df_orders.to_csv('data/sample/orders.csv')


def get_round(s_time):
    lon_lats = s_time.split(',')
    lon = round(float(lon_lats[0]), 3)
    lat = round(float(lon_lats[1]), 3)
    return str(lon) + "," + str(lat)


df_times['p1'] = df_times['p1'].apply(get_round)
df_times['p2'] = df_times['p2'].apply(get_round)
df_times.drop('Unnamed: 0', axis=1, inplace=True)
df_times.to_csv('data/sample/travel_times.csv')
